package cn.xiangxiang.mapper.order;

import cn.xiangxiang.pojo.order.CagetoryReport;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

public interface CagetoryReportMapper{

    @Select("select category_id1 categoryId1 , v.name ,category_id2 categoryId2,category_id3 categoryId3, " +
            "sum(o.pay_money) money,sum(oi.num) num,DATE_FORMAT(o.create_time,'%Y-%m-%d') coutnDate " +
            "from tb_order o INNER JOIN tb_order_item oi " +
            "on o.id = oi.order_id " + " inner join v_categorys v on  oi.category_id1 = v.id "+
            "where DATE_FORMAT(o.create_time,'%Y-%m-%d') = #{date} " +
            "GROUP BY category_id1,category_id2,category_id3 ,DATE_FORMAT(o.create_time,'%Y-%m-%d')")
    public List<CagetoryReport> countCagetoryReport(@Param("date") LocalDate date);


    @Select("select " +
            "sum(o.pay_money) money,sum(oi.num) num , v.name  from tb_order o INNER JOIN tb_order_item oi " +
            "on o.id = oi.order_id  INNER JOIN v_categorys v on category_id1 = v.id " +
            "where DATE_FORMAT(o.create_time,'%Y-%m-%d') > #{startDate} " +
            "and  DATE_FORMAT(o.create_time,'%Y-%m-%d') < #{endDate} " +
            "GROUP BY v.id")
    public List<Map> count1Category(@Param("startDate")String startDate,@Param("endDate")String endDate);
}
